package com.Dao.Imp;

import com.Dao.GetReplyDao;
import com.Utils.C3P0Utils;
import com.pojo.FindReply;
import com.pojo.Reply;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;
@Service
@Slf4j
public class GetReplyDaoImp implements GetReplyDao {

    @Override
    public List<FindReply> getReplyById(int commendId) throws SQLException {
        QueryRunner queryRunner=new QueryRunner(C3P0Utils.getDataSource());
        String sql="SELECT u.nickname,u.userAvatar,r.replyTime,r.replyText FROM userlist u JOIN reply r ON u.username=r.username WHERE r.remarkId=?";
        List<FindReply> findReplyList=queryRunner.query(sql,new BeanListHandler<>(FindReply.class),commendId);
        return  findReplyList;
    }
}
